package com.tju.resource.oauth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tju.resource.common.ServiceException;
import com.tju.resource.model.TbOutward;
import com.tju.resource.server.TbOutwardService;
import com.tju.resource.tool.result.Result;
import com.tju.resource.tool.result.ResultEnum;
import com.tju.resource.tool.result.ResultUtil;
import com.tju.resource.tool.tool.ClientParameters;
import com.tju.resource.tool.tool.QuickQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TbOutwardController {

    public static final String prefix = "oward";

    @Autowired
    TbOutwardService service;

    @PostMapping(prefix + "/getAll")
    @PreAuthorize("hasAuthority('sys:oward:list')")
    public Result<Object> getAll(@RequestBody ClientParameters params) {
        return service.getAll(params);
    }

    @PostMapping(prefix + "/add")
    @PreAuthorize("hasAuthority('sys:oward:add')")
    public Result<Object> add(@RequestBody TbOutward outward) {
        try {
            service.add(outward);

            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @PostMapping(prefix + "/upd")
    @PreAuthorize("hasAuthority('sys:oward:edit')")
    public Result<Object> upd(@RequestBody TbOutward outward) {
        try {
            service.upd(outward);

            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @PostMapping(prefix + "/del")
    @PreAuthorize("hasAuthority('sys:oward:delete')")
    public Result<Object> del(@RequestBody TbOutward outward) {
        try {
            service.del(outward.getId());

            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

}
